package jafou.server;


import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class UserHandler extends RemoteServiceServlet {
	
	private JafouEnv env = new JafouEnv();

	
	public String getLoginLogoutUrl(String type) {
		UserService userService = UserServiceFactory.getUserService();
		if(type.equalsIgnoreCase("login")){
			return userService.createLoginURL("/");
		}else if (type.equalsIgnoreCase("logout")){
			return userService.createLogoutURL("/");
		} else {
			return "";
		}
	}

	
	public String getUserId() {
		if (env.getCurrentUser() != null) {
			return env.getCurrentUser().getId() + "";
		}
		return null;
	}

	
	public boolean isLoggedIn() {
		return (env.getCurrentUser() != null);
	}

	
	public boolean isAdmin() {
		UserService userService = UserServiceFactory.getUserService();
		if(userService.getCurrentUser()!=null){
			return userService.isUserAdmin();
		}else{
			return false;
		}
	}

}
